﻿<?php 
include("conn.php");
mysql_query('SET NAMES UTF8'); 

class MyPrizeBean
{
	public $fulse;
	public $dizhiid;

	function __construct($fulse,$dizhiid)
	{
		$this->fulse      = $fulse;
		$this->dizhiid      = $dizhiid;
	}
}

$id = $_REQUEST['id'];
$did = $_REQUEST['did'];
$userid = $_REQUEST['userid'];
$province =$_REQUEST['province'];
$city =$_REQUEST['city'];
$quyu =$_REQUEST['quyu'];
$address =$_REQUEST['address'];
$phone =$_REQUEST['phone'];
$name =$_REQUEST['name'];

$prize = array();
if($id == '' && $did == ''){
	$sql = "insert into address(userid,province,city,quyu,address,tel,name) values(".$userid.",'".$province."','".$city."','".$quyu."','".$address."','".$phone."','".$name."')";
	$der = 300;
	$query = mysql_query($sql);
	$dingid = mysql_insert_id();
	if($query){
		$der = 100;
	}
	$prize[] = new MyPrizeBean($der,$dingid);
	echo json_encode($prize);
	exit;
} else if($did) {
	$sql = "update address set state = 1 where id=".$did;
	$query = mysql_query($sql);
	$prize[] = new MyPrizeBean(100,$did);
	echo json_encode($prize);
	exit;
} else if($id) {
	$sql = "update address set province = '".$province."',city = '".$city."', quyu = '".$quyu."',address ='".$address."' , tel = '".$phone."', name = '".$name."' where id=".$id;
	$query = mysql_query($sql);
	$prize[] = new MyPrizeBean(100,$id);
	echo json_encode($prize);
	exit;
} else {
	$prize[] = new MyPrizeBean(300,$did);
	echo json_encode($prize);
}



	
	
//  if($_REQUEST[userid]!=""){         


//    $states2=0;
//    $states=1;
//    $srat=mysql_query("update address set state='".$states2."' where state='".$states."' and userid ='".$_REQUEST[userid]."'");
	   
//     $quyu=$_REQUEST[city].",".$_REQUEST[quyu];
// 	$srat=mysql_query("INSERT INTO address(userid,tel,address,province,city,name) VALUES ('$_REQUEST[userid]','$_REQUEST[phone]','$_REQUEST[address]','$_REQUEST[province]','$quyu','$_REQUEST[name]')");
	  
// 	$dingid=mysql_insert_id();

// 	      if($srat==true){
// 		  	$der=100;
// 		  }
			
	
		
// 		}else {
// 		   $der=300;
// 	    }

// $prize[] = new MyPrizeBean($der,$dingid);
// echo json_encode($prize);


?>